package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.InsureInfo;
import cn.wolfcode.crm.query.InsureInfoQuery;
import cn.wolfcode.crm.service.IInsureInfoService;
import cn.wolfcode.crm.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("temporary")
public class TemporaryController {
    @Autowired
    private IInsureInfoService insureInfoService;

    //缴费
    @RequestMapping("viewPay")
    public String viewPay() {
        return "insurance/pay";
    }

    @RequestMapping("queryPay")
    @ResponseBody
    public Object queryPay(InsureInfoQuery qo) {
        qo.setState(InsureInfo.UNPAY);
        return insureInfoService.query(qo);
    }

    @RequestMapping("pay")
    @ResponseBody
    public Object pay(InsureInfo info){
        try {
            insureInfoService.pay(info);
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark(e.getMessage());
        }
        return new JsonResult();
    }
    //缴费
    @RequestMapping("viewQuery")
    public String vi() {
        return "insurance/query";
    }

    @RequestMapping("query")
    @ResponseBody
    public Object query(InsureInfoQuery qo) {
        qo.setState(InsureInfo.FINISH);
        return insureInfoService.query(qo);
    }


    //记录
    @RequestMapping("viewRecord")
    public String viewRecord() {
        return "insurance/record";
    }

    @RequestMapping("queryRecord")
    @ResponseBody
    public Object queryRecord(InsureInfoQuery qo) {
        return insureInfoService.query(qo);
    }

    //暂存单
    @RequestMapping("viewTemporary")
    public String viewTemporary() {
        return "insurance/temporary";
    }

    @RequestMapping("queryTemporary")
    @ResponseBody
    public Object queryTemporary(InsureInfoQuery qo) {
        qo.setState(InsureInfo.UNCOMMIT);//暂存单
        return insureInfoService.query(qo);
    }

    //批改单
    @RequestMapping("viewAmend")
    public String viewAmend() {
        return "insurance/amend";
    }

    @RequestMapping("queryAmend")
    @ResponseBody
    public Object queryAmend(InsureInfoQuery qo) {
        qo.setState(InsureInfo.RETURNED);//批改单
        return insureInfoService.query(qo);
    }

    //审核单
    @RequestMapping("viewAudit")
    public String viewAudit() {
        return "insurance/audit";
    }

    @RequestMapping("queryAudit")
    @ResponseBody
    public Object queryAudit(InsureInfoQuery qo) {
        qo.setState(InsureInfo.UNAUDIT);//审核单
        return insureInfoService.query(qo);
    }

    @RequestMapping("changeState")
    @ResponseBody
    public Object changeState(Long id, Integer state) {
        try {
            insureInfoService.changeState(id, state);
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark(e.getMessage());
        }
        return new JsonResult();
    }

    @RequestMapping("amend")
    @ResponseBody
    public Object amend(Long id, Integer state, String opinion) {
        try {
            insureInfoService.amend(id, state, opinion);
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult().mark(e.getMessage());
        }
        return new JsonResult();
    }

}
